// EditItemDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dq9.h"
#include "EditItemDlg.h"
#include "EditItemPanel.h"
#include "ItemListPanel.h"

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif //_DEBUG
#endif //WIND32


// EditItemDlg dialog

namespace serika
{
	namespace dq
	{
		IMPLEMENT_DYNAMIC(EditItemDlg, CDialog)

		EditItemDlg::EditItemDlg(CWnd* pParent /*=NULL*/)
			: CDialog(EditItemDlg::IDD, pParent)
			, mItemListPanel(0)
			, mIndex(0)
		{
		}

		EditItemDlg::~EditItemDlg()
		{
		}

		void EditItemDlg::DoDataExchange(CDataExchange* pDX)
		{
			CDialog::DoDataExchange(pDX);
		}

		BOOL EditItemDlg::OnInitDialog()
		{
			CDialog::OnInitDialog();

			this->MoveWindow(160, 256, 400, 600);

			mPanel.Create(EditItemPanel::IDD, this);
			CRect rect;
			this->GetClientRect(&rect);
			mPanel.MoveWindow(&rect);
			mPanel.ShowWindow(SW_SHOW);

			CWnd* wnd = this->GetDlgItem(IDOK);
			CRect clientRect;
			this->GetClientRect(&clientRect);
			wnd->GetClientRect(&rect);
			rect.MoveToXY(clientRect.right-rect.Width(), clientRect.bottom-rect.Height());
			wnd->MoveWindow(rect);
			wnd->BringWindowToTop();

			return TRUE;
		}

		BEGIN_MESSAGE_MAP(EditItemDlg, CDialog)
			ON_WM_DESTROY()
			ON_WM_SHOWWINDOW()
		END_MESSAGE_MAP()

		// EditItemDlg message handlers
		void EditItemDlg::OnDestroy()
		{
			mPanel.DestroyWindow();
		}

		void EditItemDlg::OnShowWindow(BOOL bShow, UINT nStatus)
		{
			if (bShow)
			{
				mPanel.OnActivate();
			}
			else
			{
				mPanel.OnDeactivate();
			}
		}

		void EditItemDlg::OnCancel()
		{
			CDialog::OnCancel();
			mPanel.OnDeactivate();
		}

		void EditItemDlg::OnOK()
		{
			mItemListPanel->UpdateItem(mIndex, mPanel.GetItem());
			CDialog::OnOK();
			mPanel.OnDeactivate();
		}
	}
}

